EC-CUBE 2.4.4
[ class tree: EC-CUBE 2.4.4 ] [ index: EC-CUBE 2.4.4 ] [ all elements ]

Source for file SC_FormParam.php

Documentation is available at SC_FormParam.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.lockon.co.jp/
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License
  11.  * as published by the Free Software Foundation; either version 2
  12.  * of the License, or (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  */
  23.  
  24. /* パラメータ管理クラス */
  25. class SC_FormParam {
  26.  
  27.     var $param;
  28.     var $disp_name;
  29.     var $keyname;
  30.     var $length;
  31.     var $convert;
  32.     var $arrCheck;
  33.     var $default;    // 何も入力されていないときに表示する値
  34.     var $input_db;    // DBにそのまま挿入可能か否か
  35.     var $html_disp_name;
  36.  
  37.     // コンストラクタ
  38.     function SC_FormParam({
  39.         $this->check_dir IMAGE_SAVE_DIR;
  40.         $this->disp_name = array();
  41.         $this->keyname = array();
  42.         $this->length = array();
  43.         $this->convert = array();
  44.         $this->arrCheck = array();
  45.         $this->default = array();
  46.         $this->input_db = array();
  47.     }
  48.  
  49.     // パラメータの追加
  50.     function addParam($disp_name$keyname$length=""$convert=""$arrCheck=array()$default=""$input_db="true"{
  51.         $this->disp_name[$disp_name;
  52.         $this->keyname[$keyname;
  53.         $this->length[$length;
  54.         $this->convert[$convert;
  55.         $this->arrCheck[$arrCheck;
  56.         $this->default[$default;
  57.         $this->input_db[$input_db;
  58.     }
  59.  
  60.     // パラメータの入力
  61.     // $arrVal    :$arrVal['keyname']・・の配列を一致したキーのインスタンスに格納する
  62.     // $seq        :trueの場合、$arrVal[0]~の配列を登録順にインスタンスに格納する
  63.     function setParam($arrVal$seq false{
  64.         $cnt 0;
  65.         if(!$seq){
  66.             foreach($this->keyname as $val{
  67.                 if(isset($arrVal[$val])) {
  68.                     $this->setValue($val$arrVal[$val]);
  69.                 }
  70.             }
  71.         else {
  72.             foreach($this->keyname as $val{
  73.                 $this->param[$cnt$arrVal[$cnt];
  74.                 $cnt++;
  75.             }
  76.         }
  77.     }
  78.  
  79.     // 画面表示用タイトル生成
  80.     function setHtmlDispNameArray({
  81.         $cnt 0;
  82.         foreach($this->keyname as $val{
  83.             $find false;
  84.             foreach($this->arrCheck[$cntas $val{
  85.                 if($val == "EXIST_CHECK"{
  86.                     $find true;
  87.                 }
  88.             }
  89.  
  90.             if($find{
  91.                 $this->html_disp_name[$cnt$this->disp_name[$cnt"<span class='red'>(※ 必須)</span>";
  92.             else {
  93.                 $this->html_disp_name[$cnt$this->disp_name[$cnt];
  94.             }
  95.             $cnt++;
  96.         }
  97.     }
  98.  
  99.     // 画面表示用タイトル取得
  100.     function getHtmlDispNameArray({
  101.         return $this->html_disp_name;
  102.     }
  103.  
  104.     // 複数列パラメータの取得
  105.     function setParamList($arrVal$keyname{
  106.         // DBの件数を取得する。
  107.         $count count($arrVal);
  108.         $no 1;
  109.         for($cnt 0$cnt $count$cnt++{
  110.             $key $keyname.$no;
  111.             if($arrVal[$cnt][$keyname!= ""{
  112.                 $this->setValue($key$arrVal[$cnt][$keyname]);
  113.             }
  114.             $no++;
  115.         }
  116.     }
  117.  
  118.     function setDBDate($db_date$year_key 'year'$month_key 'month'$day_key 'day'{
  119.  
  120.         if (!empty($db_date)) {
  121.             list($y$m$dsplit("[- ]"$db_date);
  122.             $this->setValue($year_key$y);
  123.             $this->setValue($month_key$m);
  124.             $this->setValue($day_key$d);
  125.         }
  126.     }
  127.  
  128.     // キーに対応した値をセットする。
  129.     function setValue($key$param{
  130.         $cnt 0;
  131.         foreach($this->keyname as $val{
  132.             if($val == $key{
  133.                 $this->param[$cnt$param;
  134.                 break;
  135.             }
  136.             $cnt++;
  137.         }
  138.     }
  139.  
  140.     function toLower($key{
  141.         $cnt 0;
  142.         foreach($this->keyname as $val{
  143.             if($val == $key{
  144.                 $this->param[$cntstrtolower($this->param[$cnt]);
  145.                 break;
  146.             }
  147.             $cnt++;
  148.         }
  149.     }
  150.  
  151.     // エラーチェック
  152.     function checkError($br true$keyname ""{
  153.         // 連想配列の取得
  154.         $arrRet $this->getHashArray($keyname);
  155.         $objErr new SC_CheckError($arrRet);
  156.  
  157.         $cnt 0;
  158.         foreach($this->keyname as $val{
  159.             foreach($this->arrCheck[$cntas $func{
  160.                 if (!isset($this->param[$cnt])) $this->param[$cnt"";
  161.                 switch($func{
  162.                 case 'EXIST_CHECK':
  163.                 case 'NUM_CHECK':
  164.                 case 'EMAIL_CHECK':
  165.                 case 'EMAIL_CHAR_CHECK':
  166.                 case 'ALNUM_CHECK':
  167.                 case 'GRAPH_CHECK':
  168.                 case 'KANA_CHECK':
  169.                 case 'URL_CHECK':
  170.                 case 'SPTAB_CHECK':
  171.                 case 'ZERO_CHECK':
  172.                 case 'ALPHA_CHECK':
  173.                 case 'ZERO_START':
  174.                 case 'FIND_FILE':
  175.                 case 'NO_SPTAB':
  176.                 case 'DIR_CHECK':
  177.                 case 'DOMAIN_CHECK':
  178.                 case 'FILE_NAME_CHECK':
  179.                 case 'MOBILE_EMAIL_CHECK':
  180.  
  181.                     if(!is_array($this->param[$cnt])) {
  182.                         $objErr->doFunc(array($this->disp_name[$cnt]$val)array($func));
  183.                     else {
  184.                         $max count($this->param[$cnt]);
  185.                         for($i 0$i $max$i++{
  186.                             $objSubErr new SC_CheckError($this->param[$cnt]);
  187.                             $objSubErr->doFunc(array($this->disp_name[$cnt]$i)array($func));
  188.                             if(count($objSubErr->arrErr0{
  189.                                 foreach($objSubErr->arrErr as $mess{
  190.                                     if($mess != ""{
  191.                                         $objErr->arrErr[$val$mess;
  192.                                     }
  193.                                 }
  194.                             }
  195.                         }
  196.                     }
  197.                     break;
  198.                 case 'MAX_LENGTH_CHECK':
  199.                 case 'MIN_LENGTH_CHECK':
  200.                 case 'NUM_COUNT_CHECK':
  201.                     if(!is_array($this->param[$cnt])) {
  202.                         $objErr->doFunc(array($this->disp_name[$cnt]$val$this->length[$cnt])array($func));
  203.                     else {
  204.                         $max count($this->param[$cnt]);
  205.                         for($i 0$i $max$i++{
  206.                             $objSubErr new SC_CheckError($this->param[$cnt]);
  207.                             $objSubErr->doFunc(array($this->disp_name[$cnt]$i$this->length[$cnt])array($func));
  208.                             if(count($objSubErr->arrErr0{
  209.                                 foreach($objSubErr->arrErr as $mess{
  210.                                     if($mess != ""{
  211.                                         $objErr->arrErr[$val$mess;
  212.                                     }
  213.                                 }
  214.                             }
  215.                         }
  216.                     }
  217.                     break;
  218.                 // 小文字に変換
  219.                 case 'CHANGE_LOWER':
  220.                     $this->param[$cntstrtolower($this->param[$cnt]);
  221.                     break;
  222.                 // ファイルの存在チェック
  223.                 case 'FILE_EXISTS':
  224.                     if($this->param[$cnt!= "" && !file_exists($this->check_dir $this->param[$cnt])) {
  225.                         $objErr->arrErr[$val"※ " $this->disp_name[$cnt"のファイルが存在しません。<br>";
  226.                     }
  227.                     break;
  228.                 default:
  229.                     $objErr->arrErr[$val"※※ エラーチェック形式($func)には対応していません ※※ <br>";
  230.                     break;
  231.                 }
  232.             }
  233.  
  234.             if (isset($objErr->arrErr[$val]&& !$br{
  235.                 $objErr->arrErr[$valereg_replace("<br>$"""$objErr->arrErr[$val]);
  236.             }
  237.             $cnt++;
  238.         }
  239.         return $objErr->arrErr;
  240.     }
  241.  
  242.     // 入力文字の変換
  243.     function convParam({
  244.         /*
  245.          *    文字列の変換
  246.          *    K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
  247.          *    C :  「全角ひら仮名」を「全角かた仮名」に変換
  248.          *    V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
  249.          *    n :  「全角」数字を「半角(ハンカク)」に変換
  250.          *  a :  「全角」英字を「半角」英字に変換
  251.          */
  252.         $cnt 0;
  253.         foreach ($this->keyname as $val{
  254.             if (!isset($this->param[$cnt])) $this->param[$cnt"";
  255.  
  256.             if(!is_array($this->param[$cnt])) {
  257.                 if($this->convert[$cnt!= ""{
  258.                     $this->param[$cntmb_convert_kana($this->param[$cnt,$this->convert[$cnt]);
  259.                 }
  260.             else {
  261.                 $max count($this->param[$cnt]);
  262.                 for($i 0$i $max$i++{
  263.                     if($this->convert[$cnt!= ""{
  264.                         $this->param[$cnt][$imb_convert_kana($this->param[$cnt][$i,$this->convert[$cnt]);
  265.                     }
  266.                 }
  267.             }
  268.             $cnt++;
  269.         }
  270.     }
  271.  
  272.     // 連想配列の作成
  273.     function getHashArray($keyname ""{
  274.         $arrRet array();
  275.         $cnt 0;
  276.         foreach($this->keyname as $val{
  277.             if($keyname == "" || $keyname == $val{
  278.                 $arrRet[$val= isset($this->param[$cnt]$this->param[$cnt"";
  279.                 $cnt++;
  280.             }
  281.         }
  282.         return $arrRet;
  283.     }
  284.  
  285.     // DB格納用配列の作成
  286.     function getDbArray({
  287.         $cnt 0;
  288.         foreach ($this->keyname as $val{
  289.             if ($this->input_db[$cnt]{
  290.                 $arrRet[$val= isset($this->param[$cnt]$this->param[$cnt"";
  291.             }
  292.             $cnt++;
  293.         }
  294.         return $arrRet;
  295.     }
  296.  
  297.     // 配列の縦横を入れ替えて返す
  298.     function getSwapArray($arrKey{
  299.         foreach($arrKey as $keyname{
  300.             $arrVal $this->getValue($keyname);
  301.             $max count($arrVal);
  302.             for($i 0$i $max$i++{
  303.                 $arrRet[$i][$keyname$arrVal[$i];
  304.             }
  305.         }
  306.         return $arrRet;
  307.     }
  308.  
  309.     // 項目名一覧の取得
  310.     function getTitleArray({
  311.         return $this->disp_name;
  312.     }
  313.  
  314.     // 項目数を返す
  315.     function getCount({
  316.         $count count($this->keyname);
  317.         return $count;
  318.     }
  319.  
  320.     // フォームに渡す用のパラメータを返す
  321.     function getFormParamList({
  322.         $cnt 0;
  323.         foreach($this->keyname as $val{
  324.  
  325.             // キー名
  326.             $arrRet[$val]['keyname'$this->keyname[$cnt];
  327.             // 文字数制限
  328.             $arrRet[$val]['length'$this->length[$cnt];
  329.             // 入力値
  330.             if (isset($this->param[$cnt])) {
  331.                 $arrRet[$val]['value'$this->param[$cnt];
  332.             }
  333.  
  334.             if (!isset($this->param[$cnt])) $this->param[$cnt"";
  335.  
  336.             if($this->default[$cnt!= "" && $this->param[$cnt== ""{
  337.                 $arrRet[$val]['value'$this->default[$cnt];
  338.             }
  339.  
  340.             $cnt++;
  341.         }
  342.         return $arrRet;
  343.     }
  344.  
  345.     // キー名の一覧を返す
  346.     function getKeyList({
  347.         foreach($this->keyname as $val{
  348.             $arrRet[$val;
  349.         }
  350.         return $arrRet;
  351.     }
  352.  
  353.     // キー名と一致した値を返す
  354.     function getValue($keyname{
  355.         $cnt 0;
  356.         foreach($this->keyname as $val{
  357.             if($val == $keyname{
  358.                 $ret = isset($this->param[$cnt]$this->param[$cnt"";
  359.                 break;
  360.             }
  361.             $cnt++;
  362.         }
  363.         return $ret;
  364.     }
  365.  
  366.     function splitCheckBoxes($keyname{
  367.         $cnt 0;
  368.         foreach($this->keyname as $val{
  369.             if($val == $keyname{
  370.                 $this->param[$cntsfSplitCheckBoxes($this->param[$cnt]);
  371.             }
  372.             $cnt++;
  373.         }
  374.     }
  375.  
  376.     function splitParamCheckBoxes($keyname{
  377.         $cnt 0;
  378.         foreach($this->keyname as $val{
  379.             if($val == $keyname{
  380.                 if(isset($this->param[$cnt]&& !is_array($this->param[$cnt])) {
  381.                     $this->param[$cntsplit("-"$this->param[$cnt]);
  382.                 }
  383.             }
  384.             $cnt++;
  385.         }
  386.     }
  387. }
  388. ?>

Documentation generated on Fri, 24 Feb 2012 14:00:06 +0900 by Seasoft